You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds runtime feature flag support to authkitLoader so applications can evaluate flags server-side using the WorkOS Feature Flags runtime client instead of relying solely on the feature_flags JWT claim. It also introduces onFeatureFlagsError for production-safe error reporting when the runtime client fails, with automatic fallback to the JWT claim.
getFeatureFlagsRuntimeClient — new module-level singleton (via the generalized lazy helper) that creates one FeatureFlagsRuntimeClient per server process; the @workos-inc/node minimum is bumped to ^8.13.0 for the required APIs.
getFeatureFlags in session.ts — new async helper called unconditionally after claims extraction; when a runtime client is configured it calls waitUntilReady (optional) then getAllFlags, filters to enabled flags, and falls back to JWT flags on any error while invoking onFeatureFlagsError and/or a debug warn.
Tests — four new scenarios cover the happy path, waitUntilReady failure, getAllFlags failure, and debug-mode logging, with proper module isolation in feature-flags.spec.ts.
Confidence Score: 5/5
Safe to merge — the new runtime flag evaluation path has clean fallback semantics and is well-tested, with no changes to the existing auth or session refresh flows.
The feature flag evaluation is fully opt-in, isolated to a new getFeatureFlags helper, and always falls back to the JWT claim on error. Existing session handling is untouched. The test suite covers the happy path, both error modes (waitUntilReady and getAllFlags failures), and debug-mode logging.
No files require special attention.
Important Files Changed
Filename
Overview
src/feature-flags.ts
New file: exports a module-level singleton getFeatureFlagsRuntimeClient using the existing lazy helper; straightforward and correct.
src/session.ts
Adds getFeatureFlags helper with onFeatureFlagsError callback and debug warn; error handling, fallback, and ordering are correct. One // istanbul ignore next comment is now redundant since a test directly covers that branch.
src/utils.ts
Generalizes lazy to accept and forward arguments on the first call; subsequent calls return the cached result regardless of arguments. Correct and well-tested.
src/interfaces.ts
Adds FeatureFlagsErrorOptions and AuthKitFeatureFlagsOptions interfaces, and extends AuthKitLoaderOptions with featureFlags and onFeatureFlagsError; types are sound.
src/feature-flags.spec.ts
Tests singleton memoization for getFeatureFlagsRuntimeClient; uses jest.resetModules and dynamic import to avoid cross-test pollution, which is the right approach.
src/session.spec.ts
Adds four new scenarios: runtime-client happy path, waitUntilReady failure fallback, getAllFlags failure fallback, and debug-mode warn. Coverage is thorough for the new code paths.
src/utils.spec.ts
New test verifies that arguments are forwarded only on the first call and the cached result is returned on subsequent calls; correctly documents lazy semantics.
src/index.ts
Re-exports getFeatureFlagsRuntimeClient from the new module; no issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getFeatureFlagsRuntimeClienthelper for the WorkOS Feature Flags runtime clientauthkitLoaderto populateauth.featureFlagsfrom a configured runtime clientonFeatureFlagsErrorso applications can report runtime evaluation failures before falling back to JWTfeature_flags@workos-inc/nodeminimum to^8.13.0for runtime-client APIsTest plan
npm run prettier./node_modules/.bin/prettier README.md --checknpm run lintnpm run typechecknpm testnpm run build